Skip to content

pin stack-tuple field order against ERC{20,721,1155}Transfer structs#439

Merged
thedavidmeister merged 2 commits intomainfrom
2026-05-04-issue-308-libflow-cast-coupling
May 4, 2026
Merged

pin stack-tuple field order against ERC{20,721,1155}Transfer structs#439
thedavidmeister merged 2 commits intomainfrom
2026-05-04-issue-308-libflow-cast-coupling

Conversation

@thedavidmeister
Copy link
Copy Markdown
Contributor

Summary

LibFlow.stackToFlow casts each consumed sentinel-tuple memory region to ERC20Transfer / ERC721Transfer / ERC1155Transfer via inline assembly. The cast assumes a fixed positional layout (token, from, to, [id,] amount) matching the rainlang author's stack convention — but the existing roundtrip tests use named-field struct construction so they silently track any reorder of the struct definition without catching divergence with the rainlang convention.

Two changes:

  1. SAFETY comments above each cast in LibFlow.stackToFlow naming the exact positional contract per token type.
  2. testFlowStackToFlowFieldOrderPinned builds a stack by hand with distinct markers per field — exactly what a rainlang author writes — and asserts each field by name on the result struct. Mutation verified: swapping from and to in ERC20Transfer makes the test fail; reverting passes.

Also bumps the rainix flake input.

Closes #308.

Test plan

  • full suite via rainix-sol-test — 28/28
  • static via rainix-sol-static — exit 0
  • mutation: swapping from/to in ERC20Transfer fails the new test (caught)

🤖 Generated with Claude Code

thedavidmeister and others added 2 commits May 4, 2026 14:20
LibFlow.stackToFlow casts each consumed sentinel-tuple memory region
to ERC20Transfer / ERC721Transfer / ERC1155Transfer via inline assembly.
The cast assumes a fixed positional layout (token, from, to, [id,]
amount) that matches the rainlang author's stack convention — but the
existing roundtrip tests use named-field struct construction so they
silently track any reorder of the struct definition without catching
the divergence with the rainlang convention.

Two changes:

1. SAFETY comments above each cast in LibFlow.stackToFlow naming the
   exact positional contract per token type.

2. testFlowStackToFlowFieldOrderPinned builds a stack by hand with
   distinct markers per field — exactly what a rainlang author writes
   — and asserts each field by name on the result struct. Mutation
   verified: swapping `from` and `to` in `ERC20Transfer` makes the
   test fail; reverting passes.

Closes #308.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

Warning

Rate limit exceeded

@thedavidmeister has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 36 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7e956573-02af-4674-92a5-c901e2cc0439

📥 Commits

Reviewing files that changed from the base of the PR and between 7a0145b and f095eaf.

⛔ Files ignored due to path filters (1)
  • flake.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • src/lib/LibFlow.sol
  • test/src/concrete/Flow.preview.t.sol
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-05-04-issue-308-libflow-cast-coupling

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 53 minutes and 36 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@thedavidmeister thedavidmeister merged commit ceaea3c into main May 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[A23-5] [LOW] LibFlow.stackToFlow: undocumented coupling between assembly cast and struct field layout

1 participant